package oj;

import java.util.Map;
import java.util.Scanner;

public class Day5S {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while (sc.hasNext()){
            int n=sc.nextInt();
            int[] arr=new int[n];
            for (int i = 0; i <arr.length ; i++) {
                arr[i]=sc.nextInt();
            }
            int sum=arr[0];
            int  count=arr[0];
            for (int i = 1; i < n; i++) {
                count= Math.max(arr[i],arr[i]+count );
                if(count>sum){
                    sum=count;
                }
            }
            System.out.println(sum);
        }
    }
}
